package cs.ubbcluj.ro.algorithm;

import cs.ubbcluj.ro.datatypes.interfaces.Vector;
import cs.ubbcluj.ro.lp.LP;

public class AlgorithmWeightedSqrt extends AlgorithmWeighted {

	public AlgorithmWeightedSqrt(LP lp, double sigma, double rho, double epsilon, double theta) {
		super(lp, sigma, rho, epsilon, theta);
	}
	
	/**
	 * instead of nu, calculate the value of 2 * (w * sqrt(x * s) - x * s)
	 * uses the same function name, so the abstraction can be done in a simpler way
	 * @return Vector
	 * @throws InterruptedException
	 */
	public Vector calculateRightHandSide(boolean useSuperClass) throws InterruptedException {		
		// calculate the value of x * s and store it in a temporary array
		Vector xs = lp.getX().createHelperVector(lp.getXLength());
		xs.set(lp.getX());
		xs.productScalar(lp.getS());
		
		// calculate w * sqrt( x * s) 
		Vector resultVector = xs.createHelperVector(xs.getNrOfRows());
		resultVector.set(xs);		
		resultVector.sqrt();
		resultVector.productScalar(lp.getW());
			
		// calculate w * sqrt( x * s) - x * s		
		resultVector.set(resultVector.diff(xs));
		
		// calculate 2 * (w * sqrt( x * s) - x * s)
		resultVector.product(2);
		
		return resultVector;
	}

}
